/*
 * @Description:类的多态
 * @Autor: HuiSir<273250950@qq.com>
 * @Date: 2021-04-29 13:50:36
 * @LastEditTime: 2021-04-30 15:18:28
 */
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* 实现了iAnimal接口的父类 */
var Animal = /** @class */ (function () {
    function Animal(type, name) {
        this.type = type;
        this.name = name;
    }
    Animal.prototype.eat = function (food) {
        var _a = this, type = _a.type, name = _a.name;
        console.log("".concat(type + name, "\u559C\u6B22\u5403").concat(food));
    };
    return Animal;
}());
/* 子类1实现多态 */
var Cat = /** @class */ (function (_super) {
    __extends(Cat, _super);
    function Cat() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Cat.prototype.eat = function (food) {
        var _a = this, type = _a.type, name = _a.name;
        console.log("".concat(type + name, "\u6B63\u5728\u5403").concat(food));
    };
    Cat.prototype.play = function () {
        var _a = this, type = _a.type, name = _a.name;
        console.log("".concat(type + name, "\u5728\u73A9\u800D"));
    };
    return Cat;
}(Animal));
/* 子类2实现多态 */
var Dog = /** @class */ (function (_super) {
    __extends(Dog, _super);
    function Dog() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Dog.prototype.eat = function (food) {
        var _a = this, type = _a.type, name = _a.name;
        console.log("".concat(type + name, "\u5403").concat(food, "\u5F88\u9999"));
    };
    return Dog;
}(Animal));
var cat = new Cat("小猫", "喵喵");
cat.eat("鱼"); // 小猫喵喵正在吃鱼
var cat2 = new Cat("小猫", "喵喵");
cat2.eat("鱼"); // 小猫喵喵正在吃鱼
cat2.play(); // 小猫喵喵在玩耍
/**
 * 不同子类的方法，同样属于父类类型
 */
var cat3 = new Cat("小猫", "喵喵");
cat3.eat("鱼"); // 小猫喵喵正在吃鱼
// cat3.play()   // 报错：类型“Animal”上不存在属性“play”。
// let cat3: Cat = new Animal("小狗", "汪汪")  // 报错：类型 "Animal" 中缺少属性 "play"，但类型 "Cat" 中需要该属性。
var dog = new Dog("小狗", "汪汪");
dog.eat("肉"); // 小狗汪汪吃肉很香
